VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmApprovalPriceDetails 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Sales Order Approval (Price Details)"
   ClientHeight    =   4785
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10005
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4785
   ScaleWidth      =   10005
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      Height          =   4680
      Left            =   45
      TabIndex        =   5
      Top             =   0
      Width           =   9930
      Begin ITGControls.ITGTextBox txtCode 
         Height          =   285
         Left            =   240
         TabIndex        =   6
         Top             =   600
         Width           =   2880
         _ExtentX        =   5080
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Customer"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1320
         TextBoxWidth    =   1500
      End
      Begin ITGControls.ITGTextBox txtName 
         Height          =   285
         Left            =   3105
         TabIndex        =   7
         Top             =   600
         Width           =   6570
         _ExtentX        =   11589
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
         Label           =   "ITGtext"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   0
         TextBoxWidth    =   6510
      End
      Begin ITGControls.ITGTextBox txtSONo 
         Height          =   285
         Left            =   240
         TabIndex        =   0
         Top             =   300
         Width           =   2880
         _ExtentX        =   5080
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Order No."
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1320
         TextBoxWidth    =   1500
      End
      Begin MSDataGridLib.DataGrid dtgSO 
         Height          =   1770
         Left            =   165
         TabIndex        =   1
         Top             =   1065
         Width           =   9555
         _ExtentX        =   16854
         _ExtentY        =   3122
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   17
         BeginProperty Column00 
            DataField       =   "cSONo"
            Caption         =   "Sales Order ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cDesc"
            Caption         =   "Product Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cPricing"
            Caption         =   "Pricing"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00000000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "cDiscount"
            Caption         =   "Discount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nNetPrice"
            Caption         =   "Net Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "cStatus"
            Caption         =   "Product Status"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "M/d/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column11 
            DataField       =   "cWH"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column12 
            DataField       =   "dDelDate"
            Caption         =   "Delivery Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column13 
            DataField       =   "nTPC"
            Caption         =   "TPC"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column14 
            DataField       =   "nSMCom"
            Caption         =   "Com %"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column15 
            DataField       =   "cRefNo"
            Caption         =   "Reference No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column16 
            DataField       =   "nSMCom"
            Caption         =   "Comm %"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1124.787
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1214.929
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   2009.764
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   555.024
            EndProperty
            BeginProperty Column04 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1200.189
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   1154.835
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Button          =   -1  'True
               ColumnWidth     =   1260.284
            EndProperty
            BeginProperty Column07 
               Object.Visible         =   0   'False
               ColumnWidth     =   1170.142
            EndProperty
            BeginProperty Column08 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1260.284
            EndProperty
            BeginProperty Column09 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   -1  'True
               ColumnWidth     =   1470.047
            EndProperty
            BeginProperty Column10 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1365.165
            EndProperty
            BeginProperty Column11 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1154.835
            EndProperty
            BeginProperty Column12 
               Object.Visible         =   0   'False
               ColumnWidth     =   1244.976
            EndProperty
            BeginProperty Column13 
               Alignment       =   1
               Object.Visible         =   0   'False
               ColumnWidth     =   780.095
            EndProperty
            BeginProperty Column14 
               Alignment       =   1
               Object.Visible         =   0   'False
               ColumnWidth     =   615.118
            EndProperty
            BeginProperty Column15 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1049.953
            EndProperty
            BeginProperty Column16 
               Alignment       =   1
               Object.Visible         =   0   'False
               ColumnWidth     =   989.858
            EndProperty
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtGross 
         Height          =   285
         Left            =   6510
         TabIndex        =   2
         Top             =   2910
         Visible         =   0   'False
         Width           =   2925
         _ExtentX        =   5159
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0.00"
         DataType        =   1
         DecimalPlace    =   2
         Locked          =   -1  'True
         Label           =   "Sub Total"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1250
         TextBoxWidth    =   1615
      End
      Begin ITGControls.ITGTextBox txtDiscount 
         Height          =   285
         Left            =   6510
         TabIndex        =   3
         TabStop         =   0   'False
         Top             =   3510
         Visible         =   0   'False
         Width           =   2925
         _ExtentX        =   5159
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0.00"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Discount"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1250
         TextBoxWidth    =   1615
      End
      Begin ITGControls.ITGTextBox txtNet 
         Height          =   285
         Left            =   6510
         TabIndex        =   4
         Top             =   3210
         Width           =   2925
         _ExtentX        =   5159
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0.00"
         DataType        =   1
         DecimalPlace    =   2
         Locked          =   -1  'True
         Label           =   "Total Amount"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1250
         TextBoxWidth    =   1615
      End
      Begin ITGControls.ITGLabel lblApproved 
         Height          =   285
         Left            =   6420
         TabIndex        =   8
         Top             =   240
         Visible         =   0   'False
         Width           =   1980
         _ExtentX        =   3493
         _ExtentY        =   503
         BackColor       =   0
         ForeColor       =   8438015
         Caption         =   "Approved"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Alignment       =   2
      End
      Begin ITGControls.ITGCommandButton cmdCancel 
         Height          =   660
         Left            =   8460
         TabIndex        =   9
         Top             =   3885
         Width           =   1290
         _ExtentX        =   2275
         _ExtentY        =   1164
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "&Cancel"
      End
      Begin ITGControls.ITGCommandButton cmdApprove 
         Height          =   660
         Left            =   7185
         TabIndex        =   10
         Top             =   3885
         Width           =   1290
         _ExtentX        =   2275
         _ExtentY        =   1164
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "&Approve"
      End
      Begin VB.Line Line1 
         X1              =   90
         X2              =   9810
         Y1              =   960
         Y2              =   960
      End
   End
End
Attribute VB_Name = "frmApprovalPriceDetails"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables
'


Private rsHeader As New ADODB.Recordset
Private rsDetail As New ADODB.Recordset

'Other declarations
Private lLessAmount As Boolean
Private lLessPercent As Boolean
Private lNetOK As Boolean

'Public mSONo As String

Private Sub cmdApprove_Click()
On Error GoTo ErrHandler
Dim OKUpdate As Boolean
    
    dtgSO_KeyPress (6)
    
    OKUpdate = False
    cn.BeginTrans
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    OKUpdate = True
    cn.CommitTrans
    
    mApprovalAction = A_Approve
    Unload Me

ErrHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "ComUnion"
        rsDetail.Requery
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "ComUnion"
        cn.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
End Sub

Private Sub cmdCancel_Click()
    mApprovalAction = A_Cancel
    Unload Me
End Sub

'After column update
Private Sub dtgSO_AfterColUpdate(ByVal ColIndex As Integer)
    Select Case ColIndex
        Case 6
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
        Case 7
            If Right(Trim(dtgSO.Columns(7).Text), 1) = "-" Then
                dtgSO.Columns(7).Text = Mid(Trim(dtgSO.Columns(7).Text), 1, Len(Trim(dtgSO.Columns(7).Text)) - 1)
                lLessAmount = False
            End If
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
    End Select
End Sub

Private Sub dtgSO_ButtonClick(ByVal ColIndex As Integer)
    Select Case ColIndex
        Case 6
            If lPickListActive Then Exit Sub
            frmITGPickList.mType = SRP
            cString = Trim(rsDetail!cItemNo)
            lModal = True
            frmITGPickList.Show vbModal
            If Trim(frmITGPickList.mCode) <> "" Then dtgSO.Columns(6).Value = CDbl(frmITGPickList.mCode)
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
    End Select
End Sub

Private Sub dtgSO_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgSO_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then cmdCancel_Click
End Sub

Private Sub dtgSO_KeyPress(KeyAscii As Integer)
    
    If rsDetail.RecordCount = 0 Then Exit Sub
        
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgSO.Col
            Case 7
                rsDetail!cDiscount = dtgSO.Columns(7).Text
                dtgSO_AfterColUpdate (7)
                dtgSO.Col = 10
                dtgSO.Columns(10).Value = rsDetail!cStatus
                If Not lNetOK Then
                    dtgSO.Col = 7
                    dtgSO.Columns(7).Value = rsDetail!cDiscount
                    Exit Sub
                End If
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        Select Case dtgSO.Col
            Case 7
                '"-" character
                If (KeyAscii = 45) And lLessAmount Then
                    KeyAscii = 0
                ElseIf KeyAscii = 45 Then
                    lLessAmount = True
                End If

                '"/" character
                If (KeyAscii = 47) And lLessPercent Then
                    KeyAscii = 0
                ElseIf KeyAscii = 47 Then
                    lLessPercent = True
                    lLessAmount = False
                Else
                    lLessPercent = False
                End If
               
                KeyAscii = ValidKeys(KeyAscii, "-/1234567890.", True)
            Case Else
                KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
        End Select
    End If
    
    
End Sub

Private Sub dtgSO_KeyUp(KeyCode As Integer, Shift As Integer)
    If rsDetail.RecordCount = 0 Then Exit Sub
    Select Case dtgSO.Col
        Case 7
            If Trim(dtgSO.Columns(7).Text) = "/" Then
                dtgSO.Columns(7).Text = ""
                lLessPercent = False
            End If
    End Select
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then
        mApprovalAction = A_Cancel
        Unload Me
    End If
End Sub

Private Sub Form_Load()
'    mSONo = Trim(frmToolApproval.mInboxRef)
    
    OpenRecordset rsDetail, "*", "SO_T", "WHERE cSONo = '" & Trim(mSONo) & "'"
    OpenRecordset rsHeader, "*", "SO", "WHERE cSONo = '" & Trim(mSONo) & "'"

    SetDataSource
    SetDataField

    If mlPApproved Then
        cmdApprove.Enabled = False
        lblApproved.Visible = True
        dtgSO.AllowUpdate = False
        dtgSO.Columns(6).Button = False
        txtDiscount.Locked = True
    End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set frmApprovalPriceDetails = Nothing
End Sub

Private Sub txtCode_Change()
    txtName = ""
    txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
End Sub

Private Sub txtDiscount_Change()
    ComputeTotal
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgSO.DataSource = rsDetail
End Sub
    
'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtSONo.DataField = !cSONO
        txtCode.DataField = !cCode
        txtGross.DataField = !nGross
        txtDiscount.DataField = !nDiscount
        txtNet.DataField = !nNet
    End With
End Sub

'Computes multi-level discount
Private Sub ComputeNet()
Dim si, l As Integer
Dim s(0 To 15), ns, disc As String
Dim lStop As Boolean
Dim net As Double

On Error GoTo ErrHandler
    
    lNetOK = True
    
    If rsDetail.RecordCount = 0 Then Exit Sub
    If IsNull(rsDetail!cItemNo) Then Exit Sub
    If Trim(rsDetail!cItemNo) = "" Then Exit Sub
    
    lNetOK = False

    rsDetail!cDiscount = Trim(dtgSO.Columns(7).Text)
    disc = rsDetail!cDiscount
    net = dtgSO.Columns(6).Value 'rsDetail!nPrice  'dtgSO.Columns(6).Value
    
    If disc <> "" Then
        l = Len(disc)
        i = 1
        si = 0
        Do While Not i = l + 1
            cString = Mid(disc, i, 1)
            If cString <> "/" Then
                ns = ns + cString
                s(si) = ns
            Else
                si = si + 1
                ns = ""
            End If
            i = i + 1
        Loop
        
        si = 0
        lStop = False
        Do While Not lStop
            If s(si) <> "" Then
                If Right(s(si), 1) = "-" Then GoTo ErrHandler
                If (Mid(s(si), 1, 1) = "-") Then
                    net = net + CDbl(s(si))
                Else
                    net = net - (net * (CDbl(s(si)) * 0.01))
                End If
                si = si + 1
            Else
                lStop = True
            End If
        Loop
    
    End If
    
    If s(0) = "" Then dtgSO.Columns(7).Text = ""
    
    dtgSO.Columns(8).Value = Round(net, 2)
    
    lNetOK = True
    
ErrHandler:
    If Not lNetOK Then
        MsgBox "Invalid discount format! (ex: '10/5/-100', '-100/10/5', '10/-100/5')", vbCritical, "ComUnion"
        lLessAmount = False
        lLessPercent = False
    End If

End Sub

'Computes total amount per detail line
Private Sub ComputeAmount()
Dim nAmount As Double
    With dtgSO
        nAmount = IIf(IsNull(.Columns(8).Value), 0, .Columns(8).Value) * _
                    IIf(IsNull(.Columns(4).Value), 0, .Columns(4).Value)
        .Columns(9).Text = Format(nAmount, "###,##0.#0")
    End With
End Sub

'Computes total amount of order
Public Sub ComputeTotal()
Dim n As Double
    
On Error Resume Next
    
    
    n = 0
    Set rs = New Recordset
    Set rs = rsDetail.Clone
    rs.Filter = "cSONo = '" & Trim(rsHeader!cSONO) & "'"

    rs.MoveFirst
    Do Until rs.EOF
        n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
        rs.MoveNext
    Loop
    Set rs = Nothing
    
    rsHeader!nGross = n
    rsHeader!nNet = n
    rsHeader!nNet = n - IIf(IsNull(rsHeader!nDiscount), 0, rsHeader!nDiscount)
    
End Sub






